0fe21d
@@ -21,7 +21,9 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.Serializable;
+import java.util.HashMap;
 import java.util.Map;
+import java.util.Properties;
 
 import org.apache.commons.lang.StringUtils;
 import org.apache.hadoop.hive.conf.HiveConf;
@@ -41,6 +43,10 @@
     
   private static final long serialVersionUID = 1L;
 
+  final static String hadoopMemKey = "HADOOP_HEAPSIZE";
+  final static String hadoopOptsKey = "HADOOP_OPTS";
+  final static String HIVE_SYS_PROP[] = {"build.dir", "build.dir.hive"}; 
+  
   public MapRedTask() {
     super();
   }
@@ -106,27 +112,50 @@
public int execute() {
       LOG.info("Executing: " + cmdLine);
       Process executor = null;
 
-      // The user can specify the hadoop memory
-      int hadoopMem = conf.getIntVar(HiveConf.ConfVars.HIVEHADOOPMAXMEM);
-
-      if (hadoopMem == 0) 
-        executor = Runtime.getRuntime().exec(cmdLine);
-      // user specified the memory - only applicable for local mode
-      else {
-        Map<String, String> variables = System.getenv();
-        String[] env = new String[variables.size() + 1];
-        int pos = 0;
+      // Inherit Java system variables
+      String hadoopOpts;
+      {
+        StringBuilder sb = new StringBuilder();
+        Properties p = System.getProperties();
+        for (int k = 0; k < HIVE_SYS_PROP.length; k++) {
+          if (p.containsKey(HIVE_SYS_PROP[k])) {
+            sb.append(" -D" + HIVE_SYS_PROP[k] + "=" + p.getProperty(HIVE_SYS_PROP[k]));
+          }
+        }
+        hadoopOpts = sb.toString();
+      }
+      
+      // Inherit the environment variables
+      String[] env;
+      {
+        Map<String, String> variables = new HashMap(System.getenv());
+        // The user can specify the hadoop memory
+        int hadoopMem = conf.getIntVar(HiveConf.ConfVars.HIVEHADOOPMAXMEM);
         
-        for (Map.Entry<String, String> entry : variables.entrySet())  
-        {  
+        if (hadoopMem == 0) {
+          variables.remove(hadoopMemKey);
+        } else {
+          // user specified the memory - only applicable for local mode
+          variables.put(hadoopMemKey, String.valueOf(hadoopMem));
+        }
+        
+        if (variables.containsKey(hadoopOptsKey)) {
+          variables.put(hadoopOptsKey, variables.get(hadoopOptsKey) + hadoopOpts);
+        } else {
+          variables.put(hadoopOptsKey, hadoopOpts);
+        }
+        
+        env = new String[variables.size()];
+        int pos = 0;
+        for (Map.Entry<String, String> entry : variables.entrySet()) {  
           String name = entry.getKey();  
           String value = entry.getValue();  
           env[pos++] = name + "=" + value;  
         }  
-        
-        env[pos] = new String("HADOOP_HEAPSIZE=" + hadoopMem);
-        executor = Runtime.getRuntime().exec(cmdLine, env);
       }
+      
+      // Run ExecDriver in another JVM
+      executor = Runtime.getRuntime().exec(cmdLine, env);
 
       StreamPrinter outPrinter = new StreamPrinter(executor.getInputStream(), null, System.out);
       StreamPrinter errPrinter = new StreamPrinter(executor.getErrorStream(), null, System.err);
